<?php

namespace app\admin\controller;


use think\Db;
use think\Request;
use app\admin\model\Rule as RuleModel;


class Con4 extends Con5
{
    public function func1()
    {
        $list = Db::table('rule')->field(['id', 'name', 'controller', 'method', 'status'])->order('id', 'asc')->select();
        return view('admin@con4/func1', [
            'list' => $list,
            'name' => $this->name
        ]);
    }

    public function func2()
    {
        return view('admin@con4/func2',[
            'name' => $this->name
        ]);
    }

    public function save(Request $request)
    {
        //ORM
        //实例化model
        $rule = new RuleModel($request->post());

        //  验证器 验证数据
        $check = $this->validate($request->post(), 'admin/Rule');

        if ($check !== true) {
            $this->error($check);
            return;
        }

//        halt($request->post());

        // 添加数据,并过滤非数据表字段
        // 返回 写入的记录数
        $result = $rule->allowField(true)->save();
//        var_dump($user);

        // 获取自订ID
        echo $rule->id;

        // 判断执行情况
        if ($result > 0) {
            return $this->success('添加成功', url('admin/con4/func1'));
        } else {
            return $this->error('添加失败,请重试!');
        }


    }

    public function delete()
    {
        echo '111111';
    }

    public function edit()
    {
        echo '11111';
    }


}
